<template>
	<view class="h-screen flex flex-col">
		<uni-nav-bar title="我的主页" fixed color="#000" statusBar backgroundColor="transparent" :border="false"
			right-icon="right" @clickRight="handleRight">
			<template v-slot:right>
				<text class="text-sm">设置</text>
				<uni-icons class="ml-6" type="gear" size="22"></uni-icons>
			</template>
		</uni-nav-bar>
		<view class="flex-1 overflow-hidden">
			<scroll-view scroll-y="true" class="h-full" @scrolltolower="onReachBottom">
				<view class="px-30">
					<template v-if="user.ach==1">
						<anchorBoxVue :val="anchor" :edit="true" class="mb-30"></anchorBoxVue>
					</template>
					<template v-else>
						<UserBoxVue :val="user" :edit="true" class="mb-30"></UserBoxVue>
					</template>
					<IncomeVue :val="user" :anchor="anchor" :isAch="user.ach" class="mb-30"></IncomeVue>
					<view class="mb-30">
						<swiper class="swiper-box" :autoplay="true">
							<swiper-item v-for="(item, index) in adList" :key="index">
								<view @click="handleGoAd('https://www.baidu.com')" class="w-full h-260 rounded-lg overflow-hidden">
									<ImageBoxVue :src="item.headimg"></ImageBoxVue>
								</view>
							</swiper-item>
						</swiper>
					</view>
					<AbilityVue class="mb-30" :isAch="user.ach"></AbilityVue>
					<TeachingVue v-if="user.ach==1" :anchor="anchor" class="mt-20"></TeachingVue>
					<template v-if="user.ach==1 && !loading">
						<BottomTabBoxVue class="mt-20" :isAch="1" :id="anchor.id" :userId="userId" v-model="page"></BottomTabBoxVue>
					</template>
					<template v-else>
						<BottomTabBoxVue class="mt-20" :isAch="0" :id="userId" v-model="page"></BottomTabBoxVue>
					</template>
				</view>
			</scroll-view>
		</view>
		<view class="px-30">
			<view class="mt-20 mb-10">
				<view class="flex flex-col justify-center items-center">
					<text>Copyright © 2025 </text>
					<text>杭州树洞文化传媒有限公司 版权所有</text>
				</view>
			</view>
		</view>
	</view>
</template>

<script setup>
	import UserBoxVue from './components/user/UserBox.vue'; //游客个人信息 
	import anchorBoxVue from './components/user/anchorBox.vue'; //主播个人信息
	import IncomeVue from './components/user/Income.vue'; //收益
	import AbilityVue from './components/user/Ability.vue'; //功能列表
	import TeachingVue from './components/user/Teaching.vue'; //我的教学
	import BottomTabBoxVue from './components/user/BottomTabBox.vue';
	import {
		ref
	} from 'vue';
	import {
		onShow,
		onLoad,
		onHide,
	} from "@dcloudio/uni-app"
	import userApi from '@/apis/apiList/userApi';
	import liveApi from '@/apis/apiList/liveApi';
	import indexApi from '@/apis/apiList/indexApi';
	const userId = ref("")
	const user = ref({})
	const anchor = ref({})
	const page = ref(1)
	const createRoomRef = ref(null)
	const adList = ref([])
	const loading = ref(false)
	const handleRight = () => {
		console.log('right')
		uni.navigateTo({
			url: `/pages/user/userSetting`
		})
	}
	// 获取个人信息
	const queryMemberInfo = () => {
		userApi.queryMemberInfo({
			id: userId.value
		}).then(res => {
			user.value = res.data
			uni.setStorageSync('user', res.data)
			if (res.data.ach == 1) {
				queryAnchorInfoByMemberId()
			} else {
				loading.value = false
			}
		})
	}
	// 获取主播信息
	const queryAnchorInfoByMemberId = () => {
		userApi.queryAnchorInfoByMemberId({
			"member.id": userId.value
		}).then(res => {
			loading.value = false
			const arr = res.data.viomsg ? res.data.viomsg.split('|') : []
			anchor.value = {
				...res.data,
				vioArr: arr
			}
			uni.setStorageSync('anchor', res.data)
		})
	}
	const handleGoAd = (src) => {
		uni.navigateTo({
			url: `/pages/views/adWebview?src=${src}`
		})
	}
	// 广告列表
	const getAdList = () => {
		const opt = {
			arrange: 1
		}
		indexApi.getBannerlistAtarrange(opt).then(res => {
			adList.value = res.data
		})
	}
	onLoad(() => {
		getAdList()
	})
	onShow(() => {
		loading.value = true
		userId.value = uni.getStorageSync('user').id
		queryMemberInfo()
	})
	onHide(() => {
		page.value = 1
	})

	const onReachBottom = () => {
		page.value++
	}
</script>

<style>
</style>